package com.hy.mydesktop.client.mvc.desktop;

import java.util.Map;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.mvc.base.BaseController;
import com.hy.mydesktop.client.mvc.util.ControllerUtil;

public class DesktopStartMenuController extends BaseController {
	
	private DesktopStartMenuView desktopStartMenuView;
	
	public DesktopStartMenuController() {
		
		//可以动态配置
	   // registerEventTypes(AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
	    
	  }

	@SuppressWarnings("unchecked")
	@Override
	public void handleEvent(AppEvent event) {
		EventStructureMetaModel eventStructureMetaModel =(EventStructureMetaModel)((Map<String, Object>)event.getData()).get("eventstructuremetamodel");
		System.out.println("StartMenuController...........");
		//0002
		if (AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER==event.getType()) {
			//通过EventStructureMetaModel识别，是否应该处理该事件
			
			System.out.println("StartMenuController...........");
			if (ControllerUtil.isHandle(eventStructureMetaModel, this)) {
//if (eventStructureMetaModel==null||this.getId()==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId().equals(this.getId())) {
				forwardToView(desktopStartMenuView, event);
				 this.forwardToChild(event);
			}
			 
		}; 
		//0003
		if (AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT==event.getType()) {
			//通过EventStructureMetaModel识别，是否应该处理该事件
			if (ControllerUtil.isHandle(eventStructureMetaModel, this)) {
//if (eventStructureMetaModel==null||this.getId()==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId().equals(this.getId())) {
				forwardToView(desktopStartMenuView, event);
				 this.forwardToChild(event);
			}
		};
		//0004
		if (AppEvents.DESKTOP_SHORTCUT_ONCLICK==event.getType()) {
			//通过EventStructureMetaModel识别，是否应该处理该事件
			if (ControllerUtil.isHandle(eventStructureMetaModel, this)) {
//if (eventStructureMetaModel==null||this.getId()==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId().equals(this.getId())) {
				forwardToView(desktopStartMenuView, event);
				 this.forwardToChild(event);
			}
		};
		//0005
		if (AppEvents.DESKTOP_STARTMENU_ONCLICK_INIT==event.getType()) {
			//通过EventStructureMetaModel识别，是否应该处理该事件
			if (ControllerUtil.isHandle(eventStructureMetaModel, this)) {
//if (eventStructureMetaModel==null||this.getId()==null||eventStructureMetaModel.getControllerId()==null||eventStructureMetaModel.getControllerId().equals(this.getId())) {
				forwardToView(desktopStartMenuView, event);
				 this.forwardToChild(event);
			}
		};
		/**
		 * 将事件转发给子节点，及子控制器
		 * 注:当前控制器，含有子节点的时候，必不可少
		 */
		//this.forwardToChild(event);
		/*枚举每一个可能需要响应的事件，以及其需要的处理方式
		ifelse switch (key) {
			case value:
				
				break;

			default:
				break;
		}*/
	}
	
	public void initialize() {
		desktopStartMenuView = new DesktopStartMenuView(this);
		 
	  }
	
	protected void onError(AppEvent ae) {
	    System.out.println("error: " + ae.<Object>getData());
	  }
}
